﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;


namespace SPMigrationOracleUtility
{
    public partial class ChangePassword : Form
    {
        public ChangePassword()
        {
            InitializeComponent();
        }
        string UserName;
        public ChangePassword(string username)
        {
            UserName = username;
            InitializeComponent();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtNewPwd.Text == txtReEnPwd.Text)
            {
                HelperClass help = new HelperClass(txtNewPwd.Text);
                help.Uname = UserName;
                help.pwd = txtOldPwd.Text;
                if (help.CheckUserExist())
                {
                    if (help.changePassword())
                    {
                        MessageBox.Show("Password has been Changed");
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Password does not matched");
                        ClearAll();

                    }
                }
                else
                {
                    MessageBox.Show("Invalid Old Password");
                    ClearAll();
                }
            }
            else
            {
                MessageBox.Show("Password & Confirm Password not matched");
                ClearAll();
            }
        }

        public void ClearAll()
        {
            txtOldPwd.Clear();
            txtNewPwd.Clear();
            txtReEnPwd.Clear();
            txtOldPwd.Focus();
        }
    }
}
